<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>PhotoSphereViewer - equirectangular tiles demo</title>

  <link rel="stylesheet" href="../dist/photo-sphere-viewer.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>

<div id="photosphere"></div>

<script src="../node_modules/three/build/three.js"></script>
<script src="../node_modules/uevent/browser.js"></script>
<script src="../dist/photo-sphere-viewer.js"></script>
<script src="../dist/adapters/equirectangular-tiles.js"></script>
<script src="../dist/plugins/gyroscope.js"></script>

<script>
  const base = 'https://photo-sphere-viewer-data.netlify.app/assets/';

  const panos = [
    {
      caption : 'Parc national du Mercantour <b>&copy; Damien Sorel</b>',
      minFov  : 30,
      position: {
        longitude: 0,
        latitude : 0,
        zoom     : 50,
      },
      config  : {
        width  : 6656,
        cols   : 16,
        rows   : 8,
        baseUrl: `${base}sphere-small.jpg`,
        tileUrl: (col, row) => {
          if (col === 8 && row === 4) {
            return 'error.jpg';
          }
          const num = row * 16 + col + 1;
          return `${base}sphere-tiles/image_part_${('000' + num).slice(-3)}.jpg`;
        },
      },
    },
    {
      caption : 'Simon\'s Town <b>&copy;  Greg Zall (HDRI Haven)</b>',
      minFov  : 10,
      position: {
        longitude: '52deg',
        latitude : 0,
        zoom     : 70
      },
      config  : {
        width  : 24576,
        cols   : 64,
        rows   : 32,
        baseUrl: `${base}sphere-tiles-24k/base.jpg`,
        tileUrl: (col, row) => {
          const num = row * 64 + col;
          return `${base}sphere-tiles-24k/tile_${('0000' + num).slice(-4)}.jpg`;
        },
      },
    }
  ];

  const viewer = new PhotoSphereViewer.Viewer({
    container : 'photosphere',
    adapter   : [PhotoSphereViewer.EquirectangularTilesAdapter, {
      showErrorTile: true,
      baseBlur     : true,
    }],
    plugins   : [
      PhotoSphereViewer.GyroscopePlugin,
    ],
    loadingImg: 'assets/photosphere-logo.gif',
    navbar    : [
      'autorotate', 'zoom',
      {
        id       : 'custom',
        title    : 'Change image',
        className: 'custom-button',
        content  : '🔄',
        onClick  : (() => {
          let i = 0;

          return () => {
            i = 1 - i;
            loadPanorama(panos[i]);
          };
        })(),
      },
      'caption', 'gyroscope', 'fullscreen',
    ],
  });

  loadPanorama(panos[0]);

  function loadPanorama(pano) {
    return viewer.setPanorama(pano.config, pano.position)
      .then(() => {
        viewer.navbar.setCaption(pano.caption);
        viewer.setOption('minFov', pano.minFov);
      });
  }
</script>
</body>
</html>
